//
//  ShouGongGoodListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/11/12.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ShouGongGoodListCell.h"

@interface ShouGongGoodListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *modelTitleLab;
@property (nonatomic, strong) UILabel *modelLab;
@property (nonatomic, strong) UILabel *yun_pieceTitleLab;
@property (nonatomic, strong) UILabel *yun_pieceLab;
@property (nonatomic, strong) UILabel *yi_pieceTitleLab;
@property (nonatomic, strong) UILabel *yi_pieceLab;
@property (nonatomic, strong) UILabel *yun_countTitleLab;
@property (nonatomic, strong) UILabel *yun_countLab;
@property (nonatomic, strong) UILabel *yi_countTitleLab;
@property (nonatomic, strong) UILabel *yi_countLab;
@property (nonatomic, strong) UIButton *lookBtn;

@end

@implementation ShouGongGoodListCell

+ (instancetype)ShouGongGoodListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ShouGongGoodListCell";
    ShouGongGoodListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ShouGongGoodListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = [UIFont systemFontOfSize:18];
        [self.bgView addSubview:self.titleLab];
        
        self.modelTitleLab = [UILabel new];
        self.modelTitleLab.textColor = HexColor(0x9C9DB3);
        self.modelTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.modelTitleLab];
        
        self.modelLab = [UILabel new];
        self.modelLab.textColor = HexColor(0x2B2C44);
        self.modelLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.modelLab];
        
        self.yun_pieceTitleLab = [UILabel new];
        self.yun_pieceTitleLab.textColor = HexColor(0x9C9DB3);
        self.yun_pieceTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yun_pieceTitleLab];
        
        self.yun_pieceLab = [UILabel new];
        self.yun_pieceLab.textColor = HexColor(0x2B2C44);
        self.yun_pieceLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yun_pieceLab];
        
        self.yi_pieceTitleLab = [UILabel new];
        self.yi_pieceTitleLab.textColor = HexColor(0x9C9DB3);
        self.yi_pieceTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yi_pieceTitleLab];
        
        self.yi_pieceLab = [UILabel new];
        self.yi_pieceLab.textColor = HexColor(0x2B2C44);
        self.yi_pieceLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yi_pieceLab];
        
        self.yun_countTitleLab = [UILabel new];
        self.yun_countTitleLab.textColor = HexColor(0x9C9DB3);
        self.yun_countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yun_countTitleLab];
        
        self.yun_countLab = [UILabel new];
        self.yun_countLab.textColor = HexColor(0x2B2C44);
        self.yun_countLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yun_countLab];
        
        self.yi_countTitleLab = [UILabel new];
        self.yi_countTitleLab.textColor = HexColor(0x9C9DB3);
        self.yi_countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yi_countTitleLab];
        
        self.yi_countLab = [UILabel new];
        self.yi_countLab.textColor = HexColor(0x2B2C44);
        self.yi_countLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.yi_countLab];
        
        self.lookBtn = [UIButton new];
        [self.lookBtn setTitle:@"选择包装" forState:0];
        [self.lookBtn setTitleColor:Color_ThemeColor forState:0];
        self.lookBtn.titleLabel.font = BoldFontOfSize(16);
        [self.lookBtn addTarget:self action:@selector(lookClick) forControlEvents:UIControlEventTouchUpInside];
        [self.lookBtn setBackgroundColor:HexColorA(0x3D68EB, 0.1)];
        self.lookBtn.layer.masksToBounds = YES;
        self.lookBtn.layer.cornerRadius = 4;
        [self.bgView addSubview:self.lookBtn];
    }
    return self;
}

- (void)lookClick {
    if (self.operationBlock) {
        self.operationBlock();
    }
}

-(void)setModel:(BillAddPackageGoodModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.titleLab.text = [NSString stringWithFormat:@"货物名称：%@",self.model.name];
    [self.titleLab sizeToFit];
    self.titleLab.nim_left = 15;
    self.titleLab.nim_top = 20;
    
    self.modelTitleLab.text = @"货物型号：";
    [self.modelTitleLab sizeToFit];
    self.modelTitleLab.nim_left = 15;
    self.modelTitleLab.nim_top = self.titleLab.nim_bottom + 10;
    
    self.modelLab.nim_left = self.modelTitleLab.nim_right;
    self.modelLab.nim_width = self.bgView.nim_width - 15 - self.modelLab.nim_left;
    self.modelLab.text = self.model.good_type;
    [self.modelLab sizeToFit];
    self.modelLab.nim_width = self.bgView.nim_width - 15 - self.modelLab.nim_left;
    self.modelLab.nim_centerY = self.modelTitleLab.nim_centerY;
    
    self.yun_pieceTitleLab.text = @"运单中件数：";
    [self.yun_pieceTitleLab sizeToFit];
    self.yun_pieceTitleLab.nim_left = 15;
    self.yun_pieceTitleLab.nim_top = self.modelTitleLab.nim_bottom + 5;
    
    self.yun_pieceLab.nim_left = self.yun_pieceTitleLab.nim_right;
    self.yun_pieceLab.nim_width = self.bgView.nim_width * 0.5 - self.yun_pieceLab.nim_left;
    self.yun_pieceLab.text = self.model.pnum;
    [self.yun_pieceLab sizeToFit];
    self.yun_pieceLab.nim_width = self.bgView.nim_width * 0.5 - self.yun_pieceLab.nim_left;
    self.yun_pieceLab.nim_centerY = self.yun_pieceTitleLab.nim_centerY;
    
    self.yi_pieceTitleLab.text = @"已扫码件数：";
    [self.yi_pieceTitleLab sizeToFit];
    self.yi_pieceTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.yi_pieceTitleLab.nim_top = self.yun_pieceTitleLab.nim_top;
    
    self.yi_pieceLab.nim_left = self.yi_pieceTitleLab.nim_right;
    self.yi_pieceLab.nim_width = self.bgView.nim_width - 15 - self.yi_pieceLab.nim_left;
    self.yi_pieceLab.text = self.model.already_jnum;
    [self.yi_pieceLab sizeToFit];
    self.yi_pieceLab.nim_width = self.bgView.nim_width - 15 - self.yi_pieceLab.nim_left;
    self.yi_pieceLab.nim_centerY = self.yi_pieceTitleLab.nim_centerY;
    
    if ([self.model.already_jnum intValue] < [self.model.pnum intValue]) {
        self.yi_pieceLab.textColor = HexColor(0xF35959);
    }else {
        self.yi_pieceLab.textColor = HexColor(0x4AD879);
    }
    
    self.yun_countTitleLab.text = @"运单中数量：";
    [self.yun_countTitleLab sizeToFit];
    self.yun_countTitleLab.nim_left = 15;
    self.yun_countTitleLab.nim_top = self.yun_pieceTitleLab.nim_bottom + 5;
    
    self.yun_countLab.nim_left = self.yun_countTitleLab.nim_right;
    self.yun_countLab.nim_width = self.bgView.nim_width * 0.5 - self.yun_countLab.nim_left;
    self.yun_countLab.text = self.model.num;
    [self.yun_countLab sizeToFit];
    self.yun_countLab.nim_width = self.bgView.nim_width * 0.5 - self.yun_countLab.nim_left;
    self.yun_countLab.nim_centerY = self.yun_countTitleLab.nim_centerY;
    
    self.yi_countTitleLab.text = @"已扫码数量：";
    [self.yi_countTitleLab sizeToFit];
    self.yi_countTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.yi_countTitleLab.nim_top = self.yun_countTitleLab.nim_top;
    
    self.yi_countLab.nim_left = self.yi_countTitleLab.nim_right;
    self.yi_countLab.nim_width = self.bgView.nim_width - 15 - self.yi_countLab.nim_left;
    self.yi_countLab.text = self.model.already_num;
    [self.yi_countLab sizeToFit];
    self.yi_countLab.nim_width = self.bgView.nim_width - 15 - self.yi_countLab.nim_left;
    self.yi_countLab.nim_centerY = self.yi_countTitleLab.nim_centerY;
    
    if ([self.model.already_num intValue] < [self.model.num intValue]) {
        self.yi_countLab.textColor = HexColor(0xF35959);
    }else {
        self.yi_countLab.textColor = HexColor(0x4AD879);
    }
    
    self.lookBtn.frame = CGRectMake(15, self.yun_countTitleLab.nim_bottom + 10, self.bgView.nim_width - 30, 42);
    
    self.bgView.nim_height = self.lookBtn.nim_bottom + 15;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
